/*
 * Script used by the game page to generate addEdge
 * requests and receive responses
 * 
 * Author: Chris Casola
 */

/**
 * React to addEdge responses
 */
function handleAddEdgeResponse(response) {	
	/* Draw the edge if the server responds with success */
	if (response.success == "true") {
		window.frame.addEdgeForm.drawEdge('blue', parseInt(response.addEdgeResponse.left), parseInt(response.addEdgeResponse.height));
		window.dlEvent.addEdge(parseInt(response.addEdgeResponse.left), parseInt(response.addEdgeResponse.height));
		updateTurnStatus();		
	}
	if (window.dlEvent.state == 3) {
		window.frame.changeForm("showResult");
	}
}

/**
 * Object to hold an addEdge request
 */
function addEdgeRequest(left, right, height) {
	this.__XMLclass = "addEdgeRequest";	
	this.id = sessionStorage['gameid'];
	this.left = left;
	this.right = right;
	this.height = height;
}

/**
 * When an edge is received update the page to display the
 * correct player turn status
 */
function updateTurnStatus() {
	if (window.dlEvent.currentPlayer == window.dlEvent.playerPosition) {
		document.getElementById('turnStatus').innerHTML = "It is your turn.";
	}
	else {
		document.getElementById('turnStatus').innerHTML = "It is not your turn.";
	}
	document.getElementById('currentRound').innerHTML = "Round: " + window.dlEvent.currentRound;
}
